/**
 * 判断设备类型(是否为移动端)
 * @returns
 */
export const envjudge = (): boolean => {
  const isMobile = window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) // 是否手机端
  return isMobile != null
}

// 防抖函数 fn：函数  time：间隔时间/ms
let timer: any = null
export function debounce (fn: any, time: number): void {
  if (typeof fn !== 'function') {
    throw new TypeError('必须传入一个函数作为参数')
  }
  timer && clearTimeout(timer)
  timer = setTimeout(() => {
    fn()
  }, time)
}

export const formatTime = (data: any) => {
  const time = data ? new Date(data) : new Date()
  const y = time.getFullYear()
  const m = time.getMonth() + 1 > 9 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1).toString()
  const d = time.getDate() > 9 ? time.getDate() : '0' + time.getDate().toString()
  return `${y}-${m}-${d}`
}
